<?php
/**
* 药品服务
*/
class MtProductSvc extends MtCommon
{
    
    /** 创建药品
     * @param $app_poi_code APP方门店ID
     * @param $app_medicine_code APP方药品id
     * @param $upc upc
     * @param $medicine_no 国药准字号
     * @param $spec 药品规格
     * @param $price 药品价格
     * @param $stock 药品库存
     * @param $category_code 药品分类code
     * @param $category_name 药品分类名称
     * @param $is_sold_out 1：卖光，0：未卖光
     */
    public function saveMedicine($app_poi_code, $app_medicine_code, $upc, $medicine_no, $spec, $price, $stock = 0, $category_code, $category_name, $is_sold_out = 1)
    {
        $data = array();
        $data['app_poi_code'] = $app_poi_code;
        $data['app_medicine_code'] = $app_medicine_code;
        $data['upc'] = $upc;
        $data['medicine_no'] = $medicine_no;
        $data['spec'] = $spec;
        $data['price'] = $price;
        $data['stock'] = 0;
        $data['category_code'] = $category_code;
        $data['category_name'] = $category_name;
        $data['is_sold_out'] = $is_sold_out;

        return $data;
    }
    /** 
     * 发送创建药品
     */
    public function sendSaveMedicine($data = array())
    {        
        $postData = $this->getPostData($data);

        $this->DLOG("saveMedicine : " . json_encode($postData, JSON_UNESCAPED_UNICODE), "run", "channel_meituan");

        $res = $this->sendData('medicine/save', $postData, 'POST');

        $this->DLOG("saveMedicine_res : " . json_encode($res, JSON_UNESCAPED_UNICODE), "run", "channel_meituan");

        return $res;
    }

    /** 更新药品
     * @param $app_poi_code APP方门店ID
     * @param $app_medicine_code APP方药品id
     * @param $upc upc
     * @param $medicine_no 国药准字号
     * @param $spec 药品规格
     * @param $price 药品价格
     * @param $stock 药品库存
     * @param $category_code 药品分类code
     * @param $category_name 药品分类名称
     * @param $is_sold_out 1：卖光，0：未卖光
     */
    public function updateMedicine($app_poi_code, $app_medicine_code, $upc, $medicine_no, $spec, $price, $stock = 0, $category_code, $category_name, $is_sold_out = 1)
    {
        $data = array();
        $data['app_poi_code'] = $app_poi_code;
        $data['app_medicine_code'] = $app_medicine_code;
        $data['upc'] = $upc;
        $data['medicine_no'] = $medicine_no;
        $data['spec'] = $spec;
        $data['price'] = $price;
        $data['stock'] = $stock;
        $data['category_code'] = $category_code;
        $data['category_name'] = $category_name;
        $data['is_sold_out'] = $is_sold_out;

        return $data;
    }
    /** 
     * 发送更新药品
     */
    public function sendUpdateMedicine($data = array())
    {        
        $postData = $this->getPostData($data);

        $this->DLOG("updateMedicine : " . json_encode($postData, JSON_UNESCAPED_UNICODE), "run", "channel_meituan");

        $res = $this->sendData('medicine/update', $postData, 'POST');

        $this->DLOG("updateMedicine_res : " . json_encode($res, JSON_UNESCAPED_UNICODE), "run", "channel_meituan");

        return $res;
    }

    /** 批量创建药品
     * @param $app_poi_code APP方门店ID
     * @param $medicine_data 同单个药品上传接口描述
     */
    public function batchSaveMedicine($app_poi_code, $medicine_data)
    {
        $data = array();
        $data['app_poi_code'] = $app_poi_code;
        $data['medicine_data'] = $medicine_data;        

        return $data;
    }
    /** 
     * 发送批量创建药品
     */
    public function sendBatchSaveMedicine($data = array())
    {        
        $postData = $this->getPostData($data);

        $this->DLOG("batchSaveMedicine : " . json_encode($postData, JSON_UNESCAPED_UNICODE), "run", "channel_meituan");

        $res = $this->sendData('medicine/batchsave', $postData, 'POST');

        $this->DLOG("batchSaveMedicine_res : " . json_encode($res, JSON_UNESCAPED_UNICODE), "run", "channel_meituan");

        return $res;
    }

    /** 批量更新药品
     * @param $app_poi_code APP方门店ID
     * @param $medicine_data 同单个药品上传接口描述
     */
    public function batchUpdateMedicine($app_poi_code, $medicine_data)
    {
        $data = array();
        $data['app_poi_code'] = $app_poi_code;
        $data['medicine_data'] = $medicine_data;        

        return $data;
    }
    /** 
     * 发送批量更新药品
     */
    public function sendBatchUpdateMedicine($data = array())
    {        
        $postData = $this->getPostData($data);

        $this->DLOG("batchUpdateMedicine : " . json_encode($postData, JSON_UNESCAPED_UNICODE), "run", "channel_meituan");

        $res = $this->sendData('medicine/batchupdate', $postData, 'POST');

        $this->DLOG("batchUpdateMedicine_res : " . json_encode($res, JSON_UNESCAPED_UNICODE), "run", "channel_meituan");

        return $res;
    }

    /** 删除药品
     * @param $app_poi_code APP方门店ID
     * @param $app_medicine_code APP方药品ID
     */
    public function deleteMedicine($app_poi_code, $app_medicine_code)
    {
        $data = array();
        $data['app_poi_code'] = $app_poi_code;
        $data['app_medicine_code'] = $app_medicine_code;        

        return $data;
    }
    /** 
     * 发送删除药品
     */
    public function sendDeleteMedicine($data = array())
    {        
        $postData = $this->getPostData($data);

        $this->DLOG("deleteMedicine : " . json_encode($postData, JSON_UNESCAPED_UNICODE), "run", "channel_meituan");

        $res = $this->sendData('medicine/delete', $postData, 'POST');

        $this->DLOG("deleteMedicine_res : " . json_encode($res, JSON_UNESCAPED_UNICODE), "run", "channel_meituan");

        return $res;
    }

    /** 查询门店药品列表
     * @param $app_poi_code APP方门店ID
     */
    public function medicineList($app_poi_code)
    {
        $data = array();
        $data['app_poi_code'] = $app_poi_code;

        return $data;
    }
    /** 
     * 发送查询门店药品列表
     */
    public function sendMedicineList($data = array())
    {        
        $postData = $this->getPostData($data);

        $this->DLOG("medicineList : " . json_encode($postData, JSON_UNESCAPED_UNICODE), "run", "channel_meituan");

        $res = $this->sendData('medicine/list', $postData, 'GET');

        $this->DLOG("medicineList_res : " . json_encode($res, JSON_UNESCAPED_UNICODE), "run", "channel_meituan");

        return $res;
    }

    /** 批量更新药品库存
     * @param $app_poi_code APP方门店ID
     * @param $medicine_data medicine_data中,app_poi_code、app_medicine_code、stock为必传字段。
药品stock不能为负数,也不能为小数,传"*"表示库存无限
     */
    public function medicineStock($app_poi_code, $medicine_data)
    {
        $data = array();
        $data['app_poi_code'] = $app_poi_code;
        $data['medicine_data'] = $medicine_data;

        return $data;
    }
    /** 
     * 发送批量更新药品库存
     */
    public function sendMedicineStock($data = array())
    {        
        $postData = $this->getPostData($data);

        $this->DLOG("medicineStock : " . json_encode($postData, JSON_UNESCAPED_UNICODE), "run", "channel_meituan");

        $res = $this->sendData('medicine/stock', $postData, 'POST');

        $this->DLOG("medicineStock_res : " . json_encode($res, JSON_UNESCAPED_UNICODE), "run", "channel_meituan");

        return $res;
    }

    /** 图片上传
     * @param $app_poi_code APP方门店ID
     * @param $img_data 图片字节流，不参与签名
     * @param $img_name 图片名称
     */
    public function uploadImage($app_poi_code, $img_data, $img_name)
    {
        $data = array();
        $data['app_poi_code'] = $app_poi_code;
        $data['img_data'] = $img_data;
        $data['img_name'] = $img_name;

        return $data;
    }
    /** 
     * 发送图片上传
     */
    public function sendUploadImage($data = array())
    {        
        $postData = $this->getPostData($data);

        $this->DLOG("uploadImage : " . json_encode($postData, JSON_UNESCAPED_UNICODE), "run", "channel_meituan");

        $res = $this->sendData('image/upload', $postData, 'POST');

        $this->DLOG("uploadImage_res : " . json_encode($res, JSON_UNESCAPED_UNICODE), "run", "channel_meituan");

        return $res;
    }
}